//
//  PaperListCell.m
//  Doctor
//
//  Created by 阳光 on 16/9/10.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "PaperListCell.h"

@interface PaperListCell ()

@property(nonatomic,strong)UIView *lineView;

// 论文图片
@property(nonatomic,strong)UIImageView *imgURL;

// 论文标题
@property(nonatomic,strong)UILabel *nameLabel;

// 论文详情
@property(nonatomic,strong)UILabel *detailLabel;

@end

@implementation PaperListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor=WhiteColor;
        
        self.imgURL.hidden=NO;
        _imgURL.image=[UIImage imageNamed:@"logo"];
        
        self.lineView.hidden=NO;
        
        self.nameLabel.font=Font_Number(16);
        
        self.detailLabel.font=Font_Number(14);
       
    }
    return self;
}

// imgURL
-(UIImageView *)imgURL
{
    if (!_imgURL) {
        _imgURL=[[UIImageView alloc]init];
        [self.contentView addSubview:_imgURL];
        [_imgURL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(kmargin);
            make.size.mas_equalTo(CGSizeMake(220/2,160/2));
        }];
    }
    return _imgURL;
}


// nameLabel
-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"你知道宝宝在子宫里的做什么吗?" font:Font_Number(16) textColor:Color000000 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imgURL.mas_right).offset(kmargin/2);
            make.top.mas_equalTo(self.imgURL.mas_top);
            make.right.mas_equalTo(-kmargin);
        }];
    }
    return _nameLabel;
}



// detailLabel
- (UILabel *)detailLabel
{
    if (!_detailLabel) {
        _detailLabel=[self getLabelWithText:@"现在,很多人来到了大城市,大城市变成了更大的城市更大的城市呀" font:Font_Number(14) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:0];
        [self.contentView addSubview:_detailLabel];
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imgURL.mas_right).offset(kmargin/2);
            make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(kmargin/2);
            make.right.mas_equalTo(-kmargin);
            make.bottom.mas_equalTo(-kmargin);
        }];
    }
    return _detailLabel;
}

-(UIView *)lineView
{
    if (_lineView==nil) {
        _lineView=[UIView new];
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin);
            make.top.mas_equalTo(self.imgURL.mas_bottom).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW-kmargin*2,.5));
        }];
        _lineView.backgroundColor=MAIN_BACK_COLOR;
    }
    return _lineView;
}

-(void)setPaperListModel:(PaperListModel *)paperListModel
{
    [_imgURL sd_setImageWithURL:[NSURL URLWithString:paperListModel.img] placeholderImage:[UIImage imageNamed:@"logo"]];
    _nameLabel.text=paperListModel.title;
    _detailLabel.text=paperListModel.content;
}

@end
